<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let obj = {
        name: "zs",
        age: 18,
        gender: "男",
        car: {
          brand: "玛莎拉蒂",
          price: 100,
        },
      };
      function clone(obj) {
        let temp = {};
        for (let k in obj) {
          if (typeof obj[k] === "object") {
            temp[k] = clone(obj[k]);
          } else {
            temp[k] = obj[k];
          }
        }
        return temp;
      }

      let result = clone(obj);
      console.log(obj);
      console.log(result);
    </script>
  </body>
</html>
